<script setup lang="ts">
import { useDeliver } from "@/views/order/deliver/utils/hook";
import Refresh from "@iconify-icons/ep/refresh";
import Van from "@iconify-icons/ep/van";
import Checked from "@iconify-icons/ep/document-checked";
import More from "@iconify-icons/ep/more-filled";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Look from "@iconify-icons/ep/view";
import Delete from "@iconify-icons/ep/delete";
import MakeIco from "@iconify-icons/ep/circle-check";

import { ref } from "vue";
const {
  form,
  loading,
  columns,
  dataList,
  pagination,
  isShow,
  onSearch,
  resetForm,
  handleSizeChange,
  handleCurrentChange,
  deviceDetection,
  handleDelete,
  onDetail,
  onFormOneClick,
  onOrderCarClick,
  onMakeList
} = useDeliver();

const formRef = ref();
</script>

<template>
  <div class="main">
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto"
    >
      <el-form-item label="关键字:">
        <el-input
          v-model="form.keyword"
          class="!w-[180px]"
          clearable
          placeholder="关键字搜索"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <div
      ref="contentRef"
      :class="['flex', deviceDetection() ? 'flex-wrap' : '']"
    >
      <PureTableBar
        :class="[isShow && !deviceDetection() ? '!w-[60vw]' : 'w-full']"
        style="transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1)"
        title="发货订单列表"
        :columns="columns"
        @refresh="onSearch"
      >
        <template v-slot="{ size, dynamicColumns }">
          <pure-table
            ref="tableRef"
            align-whole="center"
            showOverflowTooltip
            table-layout="auto"
            :loading="loading"
            :size="size"
            adaptive
            :adaptiveConfig="{ offsetBottom: 108 }"
            :data="dataList"
            :columns="dynamicColumns"
            :pagination="pagination"
            :paginationSmall="size === 'small' ? true : false"
            :header-cell-style="{
              background: 'var(--el-fill-color-light)',
              color: 'var(--el-text-color-primary)'
            }"
            @page-size-change="handleSizeChange"
            @page-current-change="handleCurrentChange"
          >
            <template #operation="{ row }">
              <el-button
                v-if="row.status === 2"
                class="reset-margin !outline-none"
                link
                type="primary"
                :size="size"
                :icon="useRenderIcon(MakeIco)"
                @click="onMakeList(row)"
              >
                生成存货单
              </el-button>
              <el-button
                class="reset-margin !outline-none"
                link
                type="primary"
                :size="size"
                :icon="useRenderIcon(Van)"
                @click="onOrderCarClick(row)"
              >
                车辆
              </el-button>
              <el-button
                class="reset-margin !outline-none"
                link
                type="primary"
                :size="size"
                :icon="useRenderIcon(Checked)"
                @click="onFormOneClick(row)"
              >
                审核
              </el-button>

              <el-dropdown>
                <el-button
                  class="ml-3 mt-[2px]"
                  link
                  type="primary"
                  :size="size"
                  :icon="useRenderIcon(More)"
                />
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item>
                      <el-button
                        class="reset-margin !outline-none"
                        link
                        type="primary"
                        :size="size"
                        :icon="useRenderIcon(Look)"
                        @click="onDetail(row)"
                      >
                        详情
                      </el-button>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-popconfirm
                        :title="`是否确认删除?`"
                        @confirm="handleDelete(row)"
                      >
                        <template #reference>
                          <el-button
                            class="reset-margin"
                            link
                            type="primary"
                            :size="size"
                            :icon="useRenderIcon(Delete)"
                          >
                            删除
                          </el-button>
                        </template>
                      </el-popconfirm>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </template>
          </pure-table>
        </template>
      </PureTableBar>
    </div>
  </div>
</template>

<style scoped lang="scss">
.main-content {
  margin: 10px 10px 0 !important;
}
</style>
